import { remark } from "remark"
import { parseMarkdownToHeader } from "./BlockTypeParsers/HeaderTypeParser"
import { parseMarkdownToParagraph } from "./BlockTypeParsers/ParagraphTypeParser"
import { parseMarkdownToList } from "./BlockTypeParsers/ListTypeParser"
import { parseMarkdownToDelimiter } from "./BlockTypeParsers/DelimiterTypeParser"
import { parseMarkdownToCode } from "./BlockTypeParsers/CodeTypeParser"
import { parseMarkdownToQuote } from "./BlockTypeParsers/QuoteTypeParser"
// import { parseMarkdownToLink } from './BlockTypeParsers/LinkTypeParser';

export const mdRender = (content) => {
	const editorData = []
	const parsedMarkdown = remark().parse(content)
	console.log("parsedMarkdown", parsedMarkdown)
	// iterating over the pared remarkjs syntax tree and executing the json parsers
	parsedMarkdown.children.forEach((item, index) => {
		switch (item.type) {
			case "heading":
				return editorData.push(parseMarkdownToHeader(item))
			case "paragraph":
				return editorData.push(parseMarkdownToParagraph(item))
			case "html":
				// 支持对md中html标签的支持
				return editorData.push({
					data: {
						text: item.value,
					},
					type: "paragraph",
				})
			case "list":
				return editorData.push(parseMarkdownToList(item))
			case "thematicBreak":
				return editorData.push(parseMarkdownToDelimiter())
			case "code":
				return editorData.push(parseMarkdownToCode(item))
			case "blockquote":
				return editorData.push(parseMarkdownToQuote(item))
			default:
				break
		}
	})

	return editorData
}

